package moxl.parser.assemblers.cdatasect;

import moxl.parser.ParserException;
import moxl.parser.assemblers.AbstractTokenFedMarkupAssembler;
import moxl.parser.assemblers.AssemblerException;
import moxl.tokenizer.TokenStream;
import moxl.tokenizer.TokenizerException;
import moxl.tokenizer.xml.XmlTokenType;

public class CharacterDataSectionAssembler extends AbstractTokenFedMarkupAssembler<CharacterDataSectionAssemblerState, CharacterDataSectionAssemblerContext>
{
	@Override
	protected CharacterDataSectionAssemblerContext createAssemblerContext(TokenStream tstream)
	{
		return new CharacterDataSectionAssemblerContext(tstream);
	}

	@Override
	protected void handleInput(XmlTokenType type, CharacterDataSectionAssemblerContext ctx) throws ParserException, TokenizerException
	{
		CharacterDataSectionStateDelegateBase delegate = ctx.getState().getDelegate();
		switch (type)
		{
		case NAME:
			delegate.acceptName(ctx);
			break;

		case OPEN_CHEVRON_EXCLAMATION_MARK:
			delegate.acceptOpenChevronExclamationMark(ctx);
			break;

		case OPEN_BRACKET:
			delegate.acceptOpenBracket(ctx);
			break;

		case CHARACTER_DATA:
			delegate.acceptCharacterData(ctx);
			break;

		case CLOSE_SECTION:
			delegate.acceptCloseSection(ctx);
			break;

		default:
			throw new AssemblerException("Parser cannot handle token: " + ctx.getToken(), ctx.getLocation());
		}
	}

}
